package com.yhy.shiro.test;

import static org.junit.Assert.assertEquals;

import java.sql.Connection;
import java.util.Iterator;
import java.util.Set;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.yhy.shiro.dao.UserDao;
import com.yhy.shiro.entity.User;
import com.yhy.util.DbUtil;

public class UserDaoTestt {
	private static DbUtil dButil = new DbUtil();
	private static Connection con = null;

	@BeforeClass
	public static void beforeClass() throws Exception {
		con = dButil.getCon();
	}

	@AfterClass
	public static void afterclass() throws Exception {
		dButil.closeCon(con);
	}

	@Test
	public void testGetUserByName() throws Exception {
		UserDao userDao = new UserDao(con);
		User user = userDao.getUserByName("yhy");
		assertEquals("123", user.getPassword());
		assertEquals(1, user.getRoleId().intValue());
	}

	@Test
	public void testGetRoleName() throws Exception {
		UserDao userDao = new UserDao(con);
		String roleName = userDao.getRoleName("yhy");
		assertEquals("teacher", roleName);
	}

	@Test
	public void testGetPerminssions() throws Exception {
		UserDao userDao = new UserDao(con);
		Set<String> perminssions = userDao.getPerminssions(1);
		assertEquals(1, perminssions.size());
		
		Iterator<String> iterator = perminssions.iterator();
		if (iterator.hasNext()) {
			assertEquals(iterator.next(), "student:*");
		}
	}
	
	
}







